package com.woniuxy.his.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.his.common.Result;
import com.woniuxy.his.entity.Medicine;
import com.woniuxy.his.service.IMedicineService;
import com.woniuxy.his.vo.AccountMedicineVo;
import com.woniuxy.his.vo.AllMedicine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@RestController
@Slf4j
@CrossOrigin("*")
public class MedicineController {

    @Resource
    private IMedicineService medicineService;

    @GetMapping("fuzzyQueryMedicine")
    public Result fuzzyQueryMedicine(String productName, @RequestParam(name = "current",defaultValue = "1")Integer current, @RequestParam(name = "pageSize",defaultValue = "7") Integer pageSize){
        log.info("药品名={},当前页{}，,页容量{}",productName,current,pageSize);
        IPage<Medicine> medicineIPage = medicineService.findMedicineLikeName(productName, current, pageSize);
        return Result.success("20000","查询成功",medicineIPage);
    }

    //药品划价后,传递项目信息,写入检查表和检查详情表
    @PostMapping("/accountMedicine")
    public Result accountMedicine(@RequestBody AccountMedicineVo accountMedicineVo){
        log.info("tableMedicine={},totalMedicine={},guaId={},doctorId={}",accountMedicineVo.getTableMedicine(),accountMedicineVo.getTotalMedicine(),accountMedicineVo.getGuaId(),accountMedicineVo.getDoctorId());

        Integer i = medicineService.accountMedicine(accountMedicineVo);

        return i>0?Result.success("1111","成功",i):Result.fail("0000","失败",i);
    }

    //获取药品库所有的数据信息
    @GetMapping("/getAllMedicine")
    public Result getAllMedicine(
            @RequestParam(name = "pageSize", defaultValue = "10") int pageSize,
            @RequestParam(name = "current" , defaultValue = "1") int current){

        log.info("页容量：pageSize={},当前页：current={}",pageSize,current);

        IPage iPage = medicineService.getAllMedicine(current, pageSize);

        return iPage==null?Result.fail("0000","没找到",iPage):Result.success("1111","找到了",iPage);

    }

}

